/*
 * User.java
 */

package model;

/**
 * User class represents a User in the Urban Parks program.
 * 
 * @author Carlo Consolacion
 * @author Sean Brown
 * @author Doug Hutchens
 * @version 1.0
 */
public class User implements Cloneable {

	/**
	 * The first name of this User.
	 */
	private final String my_first_name;

	/**
	 * The last name of this User.
	 */
	private final String my_last_name;

	/**
	 * The email address for this User (used for identification and login).
	 */
	private String my_email;

	/**
	 * The Phone Number for contacting this User.
	 */
	private PhoneNumber my_phone_number;

	/**
	 * The Role of the User.
	 */
	private final Role my_role;

	/**
	 * The ID number for the User.
	 */
	private final int my_id;

	/**
	 * The blackball comments for the user.
	 */
	private String my_comments;

	/**
	 * Whether or not this user is blackballed.
	 */
	private boolean my_is_blackballed;

	/**
	 * The address of this User.
	 */
	private PostalAddress my_postal_address;

	/**
	 * Constructor for a User, instantiates all objects and assigns values to
	 * fields.
	 * 
	 * @assumes all params are non-null.
	 * @param the_first_name
	 *            , the user's first name in string
	 * @param the_last_name
	 *            , the use's last name in string
	 * @param the_email
	 *            , the user's email address in string
	 * @param the_phone_number
	 *            , the user's phone number in phone number object format
	 * @param the_role
	 *            , the user's role in term of the enum
	 * @param the_comments
	 *            , the added comments for this user in string
	 * @param the_postal_address
	 *            , the user's postal address in postal address format
	 */
	public User(final String the_first_name, final String the_last_name,
			final String the_email, final PhoneNumber the_phone_number,
			final Role the_role, final String the_comments,
			final PostalAddress the_postal_address,
			final boolean the_is_blackballed) {
		my_first_name = the_first_name;
		my_last_name = the_last_name;
		my_email = the_email;
		my_phone_number = the_phone_number;
		my_role = the_role;
		my_comments = the_comments;
		my_postal_address = the_postal_address;
		my_is_blackballed = the_is_blackballed;
		my_id = hashCode();
	}

	/**
	 * The method to get the user's full name (first, name)
	 * 
	 * @return the user's full name in string
	 */
	public String getName() {
		String full_name = my_first_name + " " + my_last_name;
		return full_name;
	}

	/**
	 * The method to get the user's first name
	 * 
	 * @return the user's first name in string
	 */
	public String getFirstName() {
		return my_first_name;
	}

	/**
	 * The method to get the user's last name
	 * 
	 * @return the user's last name in string
	 */
	public String getLastName() {
		return my_last_name;
	}

	/**
	 * The method to get user's email address
	 * 
	 * @return the user's email address in string
	 */
	public String getEmail() {
		return my_email;
	}

	/**
	 * The method to allow program to update the user's email address
	 * 
	 * @param the_email
	 *            , the email address "we" want to update to the user's email
	 *            address's field
	 */
	public void setEmail(final String the_email) {
		my_email = the_email;
	}

	/**
	 * The method to get user's postal address
	 * 
	 * @return the user's postal address.
	 */
	public PostalAddress getPostalAddress() {
		return my_postal_address;
	}

	/**
	 * The method to get user's phone number
	 * 
	 * @return the user's phone number in phone number format(defined in
	 *         PhoneNumber class)
	 */
	public PhoneNumber getPhoneNumber() {
		return my_phone_number;
	}

	/**
	 * The method to get user's role(staff / manager / volunteer)
	 * 
	 * @return the user's role
	 */
	public Role getRole() {
		return my_role;
	}

	/**
	 * The method to get user's ID(define by User class's hash code function)
	 * 
	 * @return the user's ID in integer
	 */
	public int getID() {
		return my_id;
	}

	/**
	 * The method to get user's comments(comments added by staff member)
	 * 
	 * @return the user's comment in string
	 */
	public String getComments() {
		return my_comments;
	}

	/**
	 * The method to allow the program(when staff member logged in) to update
	 * the comments for the user
	 * 
	 * @param the_comments
	 *            , the comments to be added to the user's comment field
	 */
	public void setComments(final String the_comments) {
		my_comments = the_comments;
	}

	/**
	 * The method to check is the user is black balled
	 * 
	 * @return true or false in term of wither if the user(volunteer) is black
	 *         balled
	 */
	public boolean isBlackballed() {
		return my_is_blackballed;
	}

	/**
	 * The method to allow the program to black ball a user(volunteer)
	 * 
	 * @param the_isBlackballed
	 *            the flag to set the user black balled or not black balled
	 */
	public void setBlackballed(final boolean the_isBlackballed) {
		if (the_isBlackballed == true) {
			my_is_blackballed = true;
		} else {
			my_is_blackballed = false;
		}
	}

	/**
	 * This method overrides the hashCode method.
	 */
	@Override
	public int hashCode() {
		return my_email.toLowerCase().hashCode();
	}

	/**
	 * This method overrides the equals method.
	 */
	@Override
	public boolean equals(final Object obj) {
		boolean equal = false;
		if (obj != null && getClass() == obj.getClass()) {
			equal = ((User) obj).hashCode() == hashCode();
		}
		return equal;
	}

	/**
	 * This method overrides the toString method.
	 */
	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		final String nl = "\n";
		sb.append("User: ");
		sb.append(my_first_name);
		sb.append(" ");
		sb.append(my_last_name);
		sb.append(nl);
		sb.append("Email: ");
		sb.append(my_email);
		sb.append(nl);
		sb.append("Phone Number: ");
		sb.append(my_phone_number);
		sb.append(nl);
		sb.append("Role: ");
		sb.append(my_role);
		sb.append(nl);
		sb.append("Comments: ");
		sb.append(my_comments);
		sb.append(nl);
		sb.append("Address: ");
		sb.append(my_postal_address);
		sb.append(nl);
		sb.append("Blackballed = ");
		sb.append(my_is_blackballed);
		sb.append(nl);
		sb.append("ID#: ");
		sb.append(my_id);
		return sb.toString();
	}

	/**
	 * This method overrides the clone method.
	 */
	@Override
	public Object clone() {
		return new User(my_first_name, my_last_name, my_email,
				(PhoneNumber) my_phone_number.clone(), my_role, my_comments,
				(PostalAddress) my_postal_address.clone(), my_is_blackballed);
	}

}
